import _got from "got";

import { Resolvers } from "../generated/graphql";
// import sql from "../sql";
import * as busi from "../busi";
import * as util from "../util";
// import { sys_app_info } from "../generated/sts_traffic_portal";

const got = _got.extend({
  prefixUrl: "http://sts.didichuxing.com/api",
  searchParams: "token=ba811d5abee2f3b6281ee5725d6279f3",
});

export const open_platform: Resolvers = {
  Query: {
    op__tti__req_traffic_ratio: async (_, args, ctx, info) => {
      const res: any = await got.post("tti/req_traffic_ratio", { json: args }).json();
      return res.res;
    },
    op__tti__req_traffic_ratio_s: async (_, args, ctx, info) => {
      const res: any = await got.post("tti/req_traffic_ratio", { json: args }).json();
      return res.res;
    },
    op__tti__tti_info_by_id: async (_, args, ctx, info) => {
      const args_clone = JSON.parse(JSON.stringify(args));
      args_clone.obj_ids = args_clone.obj_ids.join(",");
      const res: any = await got.post("tti/tti_info_by_id", { json: args_clone }).json();
      return res.res;
    },
    op__tti__ids: async (_, args, ctx, info) => {
      const res: any = await got.post("tti/ids", { json: args }).json();
      return res.res;
    },
    op__cityweather_info_tqw: async (_, args, ctx, info) => {
      args.caller = args.caller || 'map_tools_traffic_gov';
      const res: any = await got.post("weather/cityweather_info_tqw", { json: args }).json();
      return res.value;
    }
  },
  op__tti__ids: {
    _24hours_spd_last: _ => (_ as any)["24hours_spd_last"],
    _24hours_spd: _ => (_ as any)["24hours_spd"],
    _7days_spd_last: _ => (_ as any)["7days_spd_last"],
    _7days_spd: _ => (_ as any)["7days_spd"],
    _7days_tti_last: _ => (_ as any)["7days_tti_last"],
    _24hours_tti_last: _ => (_ as any)["24hours_tti_last"],
    _24hours_tti: _ => (_ as any)["24hours_tti"],
    _7days_tti: _ => (_ as any)["7days_tti"],
  },
};
